package cate.game.server.configuration.dao;

import cate.common.game.GameCollection;
import cate.game.db.GameMongoDao;
import cate.game.role.res.guild.boss.GuildBossRankSPO;
import cate.game.role.res.guild.po.GuildPO;
import cate.game.server.configuration.dao.game.*;
import cate.game.server.configuration.dao.role.*;
import com.mongodb.client.MongoDatabase;
import easy.java.runtime.reflect.ClassReflect;

public class MgDaoSetup {

    MongoDatabase database;
    GameMongoDao mongoDao;

    public MgDaoSetup(MongoDatabase database, GameMongoDao mongoDao) {
        this.database = database;
        this.mongoDao = mongoDao;
    }

    public void exe() {
        mongoDao.roleBase = build(MgRoleBaseDao.class, GameCollection.NAME_ROLE_BASE);
        mongoDao.roleBag = build(MgRoleBagDao.class, GameCollection.NAME_ROLE_BAG);
        mongoDao.roleFight = build(MgRoleFightDao.class, GameCollection.NAME_ROLE_FIGHT);
        mongoDao.roleMail = build(MgRoleMailDao.class, GameCollection.NAME_ROLE_MAIL);
        mongoDao.roleFriend = build(MgRoleFriendDao.class, GameCollection.NAME_ROLE_FRIEND);
        mongoDao.roleMall = build(MgRoleMallDao.class, GameCollection.NAME_ROLE_MALL);
        mongoDao.roleChat = build(MgRoleChatDao.class, GameCollection.NAME_ROLE_CHAT);
        mongoDao.rolePay = build(MgRolePayDao.class, GameCollection.NAME_ROLE_PAY);
        mongoDao.roleWorld = build(MgRoleWorldDao.class, GameCollection.NAME_ROLE_WORLD);
        mongoDao.roleNote = build(MgRoleNoteDao.class, GameCollection.NAME_ROLE_NOTE);
        mongoDao.roleSystem = build(MgRoleSystemDao.class, GameCollection.NAME_ROLE_SYSTEM);
        mongoDao.status = build(MgRoleStatusDao.class, GameCollection.NAME_ROLE_STATUS);
        mongoDao.res = build(MgRoleResDao.class, GameCollection.NAME_ROLE_RES);
        mongoDao.farm = build(MgRoleFarmDao.class, GameCollection.NAME_ROLE_FARM);
        mongoDao.pvp = build(MgRolePvpDao.class, GameCollection.NAME_ROLE_PVP);
        mongoDao.activity = build(MgRoleActivityDao.class, GameCollection.NAME_ROLE_ACTIVITY);
        mongoDao.task = build(MgRoleTaskDao.class, GameCollection.NAME_ROLE_TASK);
        mongoDao.history = build(MgRoleHistoryDao.class, GameCollection.NAME_ROLE_HISTORY);
        mongoDao.show = build(MgRoleShowDao.class, GameCollection.NAME_ROLE_SHOW);
        mongoDao.trace = build(MgRoleTraceDao.class, GameCollection.NAME_ROLE_TRACE);

        mongoDao.kv = build(MgKvDao.class, GameCollection.NAME_KV);
        mongoDao.rank = build(MgRankDao.class, GameCollection.NAME_RANK);
        mongoDao.mailBox = build(MgMailBoxDao.class, GameCollection.NAME_MAILBOX);
        mongoDao.play = build(MgPlayDao.class, GameCollection.NAME_PLAY);
        mongoDao.guild = build(MgGuildDao.class, GuildPO.COLLECTION);
        mongoDao.heroDisplay = build(MgHeroDisplayDao.class, GameCollection.NAME_HERO_DISPLAY);
        mongoDao.gameStatus = build(MgGameStatusDao.class, GameCollection.NAME_STATUS);
        mongoDao.friendBox = build(MgFriendBoxDao.class, GameCollection.NAME_FRIENDBOX);
        mongoDao.guildBossRank = build(MgGuildBossRankDao.class, GuildBossRankSPO.COLLECTION);
    }

    private <T extends MgRepo> T build(Class<T> daoClz, String collectionName) {
        T t = ClassReflect.newInstance(daoClz);
        t.init(database.getCollection(collectionName));
        return t;
    }
}
